package zhihui.mobile.presenter.coupon;

import android.content.Context;

import java.util.ArrayList;
import java.util.List;

import zhihui.mobile.bean.shop.sales.CouponInfo;
import zhihui.mobile.manager.shop.CouponManager;
import zhihui.mobile.ui.IView;
import zhihui.mobile.ui.shop.coupon.ICouponContract;

/**
 * Created by 张公铭 on 2017/9/11 0011.
 */

public class CouponPresenter implements ICouponContract.ICouponPresenter
{
    private Context mContext;
    private ICouponContract.ICouponView couponView;

    @Override
    public void init(IView view, Context context)
    {
        mContext = context;
        couponView = (ICouponContract.ICouponView) view;
    }

    @Override
    public void onResume()
    {

    }

    @Override
    public void onStart()
    {

    }

    @Override
    public void onPause()
    {

    }

    @Override
    public void onStop()
    {

    }

    @Override
    public void onDestroy()
    {

    }

    @Override
    public void getCouponListByState(int state)
    {
        List<CouponInfo> list = new ArrayList<>();
        int unusedNum = 0;
        int useNum = 0;
        int timeoutNum = 0;

        for (CouponInfo couponInfo : CouponManager.getInstance().getmList())
        {
            if (state == couponInfo.getStatus())
            {
                list.add(couponInfo);
            }
            switch (couponInfo.getStatus())
            {
                case 1:
                    unusedNum+=1;
                    break;
                case 2:
                    useNum+=1;
                    break;
                case 3:
                    timeoutNum+=1;
                    break;
            }

        }


        couponView.refreshCoupons(list, unusedNum, useNum, timeoutNum);
    }
}
